<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$grassset=$this->plugin_setting('video');
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['params']['groupid']=0;
	$postdata=get_postdata();
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
    $orderby='id desc';
	$total='';
	$return['groups']=pdo_getslice('jy_weishop_video_group',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	if($_RQ['groupid'] || $_RQ['group_id']){
		$params['groupid']=intval($_RQ['groupid'])?:intval($_RQ['group_id']);
		$return['params']['groupid']=intval($_RQ['groupid'])?:intval($_RQ['group_id']);
	}
	$return['list']=pdo_getslice('jy_weishop_video',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$item){
		$item['images']=json_decode($item['images'],true);
	}
	$return['sharedata']=array(
		'title'=>$grassset['title']?$grassset['title']:'视频列表',
		'desc'=>$grassset['desc']?$grassset['desc']:'视频详情',
		'link'=>custom_url('jy_weishop/video.index/',true),
		'imgUrl'=>tomedia($grassset['image']),
	);
	set_html('title',$grassset['title']?:'视频列表');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	if($_RQ['groupid'] || $_RQ['group_id']){
		$params['groupid']=intval($_RQ['groupid'])?:intval($_RQ['group_id']);
		$return['params']['groupid']=intval($_RQ['groupid'])?:intval($_RQ['group_id']);
	}
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_weishop_video',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$item){
		$item['image']=tomedia($item['image']);
		$item['images']=json_decode($item['images'],true);
		$pindex = max(1, 0);
		$members=pdo_getslice('jy_weishop_video_looklist',array('uniacid'=>$_SESSION['uniacid'],'oid'=>$item['id']),array($pindex,5),$total,array('mid'),'','id desc');
		foreach($members as &$mv){
			$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
			$mv['nickname']=$memberinfo['nickname'];
			$mv['avatar']=tomedia($memberinfo['avatar']);
		}
		$item['members']=$members;
		$item['likes']=pdo_count('jy_weishop_video_like',array('uniacid'=>$_SESSION['uniacid'],'oid'=>$item['id']),'id');
	}
	exi($return);
}
?>